﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;
using NLite.Reflection;

namespace NLite.Mapping.Internal
{
    sealed class DataTableMapper : MapperBase
    {
        private bool isFromDataTable;
        public DataTableMapper(Type fromType, Type toType)
            : base(fromType, toType)
        {
            isFromDataTable = Types.DataTable.IsAssignableFrom(fromType);
        }

        public override void Map(ref object from, ref object to)
        {
            if (isFromDataTable)
                new DataReaderMapper(_Info.To).Map(ref from, ref to);
            else
            {
                var list = from as IList;
                if (to == null)
                {
                    var dt = ObjectCreator.Create(_Info.To) as DataTable;
                    ListToDataTable(list, dt);
                    to = dt;
                }
            }

        }

        private void ListToDataTable(IList from, DataTable to)
        {

        }
    }
}
